<template>
  <div id="recruitTable">
    <el-dialog :title="dialogTitle" :visible.sync="editFormVisible" width="98%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form :model="editForm" label-width="200px" ref="editForm" :inline="true" style="padding:10px 0 0;clear:both" inline-message :rules="editFormRules">
        <table cellspacing="0" cellpadding="0" class="mytable">
          <tr>
            <th style="vertical-align: middle;">单位名称</th>
            <td style="vertical-align: middle;" colspan="5">
              <el-form-item prop="unitName">
                <el-input v-model="editForm.unitName" style="width:500px"></el-input>
              </el-form-item>
            </td>
          </tr>
          <template v-if="theType===1">
            <template v-if="dialogUnitBeijing===1">
              <tr>
                <th style="vertical-align: middle;text-align:left" colspan="6">京内生源</th>
              </tr>
              <tr>
                <th style="vertical-align: middle;">大专</th>
                <td style="vertical-align: middle;">
                  <el-form-item prop="countBeijing1">
                    <el-input-number v-model="editForm.countBeijing1" />
                  </el-form-item>
                </td>
                <th style="vertical-align: middle;">本科生</th>
                <td style="vertical-align: middle;" colspan="3">
                  <el-form-item prop="countBeijing2">
                    <el-input-number v-model="editForm.countBeijing2" />
                  </el-form-item>
                </td>
              </tr>
              <tr>
                <th style="vertical-align: middle;">硕士研究生</th>
                <td style="vertical-align: middle;">
                  <el-form-item prop="countBeijing3">
                    <el-input-number v-model="editForm.countBeijing3" />
                  </el-form-item>
                </td>
                <th style="vertical-align: middle;">博士研究生</th>
                <td style="vertical-align: middle;">
                  <el-form-item prop="countBeijing4">
                    <el-input-number v-model="editForm.countBeijing4" />
                  </el-form-item>
                </td>
                <th style="vertical-align: middle;">其他</th>
                <td style="vertical-align: middle;">
                  <el-form-item prop="countBeijing5">
                    <el-input-number v-model="editForm.countBeijing5" />
                  </el-form-item>
                </td>
              </tr>
            </template>
            <tr>
              <th style="vertical-align: middle;text-align:left" colspan="6">{{dialogUnitBeijing===2?'招生计划':'京外生源'}}</th>
            </tr>
              <tr>
                <th style="vertical-align: middle;">大专</th>
                <td style="vertical-align: middle;">
                  <el-form-item prop="count1">
                    <el-input-number v-model="editForm.count1" />
                  </el-form-item>
                </td>
                <th style="vertical-align: middle;">本科生</th>
                <td style="vertical-align: middle;" colspan="3">
                  <el-form-item prop="count2">
                    <el-input-number v-model="editForm.count2" />
                  </el-form-item>
                </td>
              </tr>
              <tr>
                <th style="vertical-align: middle;">硕士研究生</th>
                <td style="vertical-align: middle;">
                  <el-form-item prop="count3">
                    <el-input-number v-model="editForm.count3" />
                  </el-form-item>
                </td>
                <th style="vertical-align: middle;">博士研究生</th>
                <td style="vertical-align: middle;">
                  <el-form-item prop="count4">
                    <el-input-number v-model="editForm.count4" />
                  </el-form-item>
                </td>
                <th style="vertical-align: middle;">其他</th>
                <td style="vertical-align: middle;">
                  <el-form-item prop="count5">
                    <el-input-number v-model="editForm.count5" />
                  </el-form-item>
                </td>
              </tr>
          </template>
          <tr v-else>
            <th style="vertical-align: middle;">编制（员工控制数）</th>
            <td style="vertical-align: middle;" colspan="5">
              <el-form-item prop="title">
                <el-input-number v-model="editForm.inServicePersonCount" />
              </el-form-item>
            </td>
          </tr>
        </table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click.native="editFormSubmit" :loading="editLoading">保存</el-button>
        <el-button @click.native="editFormVisible = false">取消</el-button>
      </div>
    </el-dialog>
    <template v-if="unitBeijing!==2">
      <el-button v-if="userType==2&&state===0" icon="el-icon-plus" type="success" style="float:right;margin-left:10px" @click="handleAdd(1,1)">新增</el-button>
      <el-button icon="el-icon-download" type="primary" style="float:right" @click="handleExport(1,1)">导出</el-button>
      <h1 style="text-align:center">{{theYear}}年度应届毕业生招聘计划表（京内单位填写）</h1>
      <el-table :data="list1" highlight-current-row v-loading="listLoading" style="width: 100%;margin-bottom: 20px;" show-summary>
        <el-table-column prop="unitName" label="单位名称" min-width="150">
        </el-table-column>
        <el-table-column prop="sy" label="京内生源" width="80" align="center">
          <el-table-column prop="countBeijing1" width="70" label="大专" align="center" >
            <template slot-scope="scope">
              {{scope.row.countBeijing1?scope.row.countBeijing1:''}}
            </template>
          </el-table-column>
          <el-table-column prop="countBeijing2" width="70" label="本科生" align="center" >
            <template slot-scope="scope">
              {{scope.row.countBeijing2?scope.row.countBeijing2:''}}
            </template>
          </el-table-column>
          <el-table-column prop="countBeijing34" width="70" label="研究生" align="center" >
            <template slot-scope="scope">
              {{(scope.row.countBeijing34)?(scope.row.countBeijing34):''}}
            </template>
          </el-table-column>
          <el-table-column prop="countBeijing5" width="70" label="其他" align="center" >
            <template slot-scope="scope">
              {{scope.row.countBeijing5?scope.row.countBeijing5:''}}
            </template>
          </el-table-column>
          <el-table-column prop="sum1" width="60" label="小计" align="center" >
            <template slot-scope="scope">
              {{scope.row.sum1?scope.row.sum1:''}}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column prop="sy" label="京外生源" width="80" align="center">
          <el-table-column prop="count1" width="70" label="大专" align="center" >
            <template slot-scope="scope">
              {{scope.row.count1?scope.row.count1:''}}
            </template>
          </el-table-column>
          <el-table-column prop="count2" width="70" label="本科生" align="center" >
            <template slot-scope="scope">
              {{scope.row.count2?scope.row.count2:''}}
            </template>
          </el-table-column>
          <el-table-column prop="count34" width="70" label="研究生" align="center" >
            <template slot-scope="scope">
              {{(scope.row.count34)?(scope.row.count34):''}}
            </template>
          </el-table-column>
          <el-table-column prop="count5" width="70" label="其他" align="center" >
            <template slot-scope="scope">
              {{scope.row.count5?scope.row.count5:''}}
            </template>
          </el-table-column>
          <el-table-column prop="sum2" width="60" label="小计" align="center" >
            <template slot-scope="scope">
              {{scope.row.sum2?scope.row.sum2:''}}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="操作" width="120" v-if="userType==2&&state===0" key="edit">
          <template slot-scope="scope">
            <el-dropdown split-button  @click="handleDetail(scope.row,1,1)" size="small" type="primary" :loading="btnLoading">
              修改
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleDel(scope.row.id)" >删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <template v-if="unitBeijing!==1">
      <el-button v-if="userType==2&&state===0" icon="el-icon-plus" type="success" style="float:right;margin-left:10px" @click="handleAdd(1,2)">新增</el-button>
      <el-button icon="el-icon-download" type="primary" style="float:right" @click="handleExport(1,2)">导出</el-button>
      <h1 style="text-align:center">{{theYear}}年度应届毕业生招聘计划表（京外单位填写）</h1>
      <el-table :data="list2" highlight-current-row v-loading="listLoading" style="width: 100%;margin-bottom: 20px;" show-summary>
        <el-table-column prop="unitName" label="单位名称" min-width="150">
        </el-table-column>
        <el-table-column label="招聘计划" width="80" align="center">
          <el-table-column prop="count1" width="70" label="大专" align="center" >
            <template slot-scope="scope">
              {{scope.row.count1?scope.row.count1:''}}
            </template>
          </el-table-column>
          <el-table-column prop="count2" width="70" label="本科生" align="center" >
            <template slot-scope="scope">
              {{scope.row.count2?scope.row.count2:''}}
            </template>
          </el-table-column>
          <el-table-column prop="count34" width="70" label="研究生" align="center" >
            <template slot-scope="scope">
              {{(scope.row.count34)?(scope.row.count34):''}}
            </template>
          </el-table-column>
          <el-table-column prop="count5" width="70" label="其他" align="center" >
            <template slot-scope="scope">
              {{scope.row.count5?scope.row.count5:''}}
            </template>
          </el-table-column>
          <el-table-column prop="sum2" width="60" label="小计" align="center" >
            <template slot-scope="scope">
              {{scope.row.sum2?scope.row.sum2:''}}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="操作" width="120" v-if="userType==2&&state===0" key="edit2">
          <template slot-scope="scope">
            <el-dropdown split-button  @click="handleDetail(scope.row,1,2)" size="small" type="primary" :loading="btnLoading">
              修改
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleDel(scope.row.id)" >删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <template>
      <el-button v-if="userType==2&&state===0" icon="el-icon-plus" type="success" style="float:right;margin-left:10px" @click="handleAdd(2)">新增</el-button>
      <el-button icon="el-icon-download" type="primary" style="float:right" @click="handleExport(2)">导出</el-button>
      <h1 style="text-align:center">{{theYear}}年度在职人员招聘计划表</h1>
      <el-table :data="list3" highlight-current-row v-loading="listLoading" style="width: 100%;margin-bottom: 20px;" show-summary>
        <el-table-column prop="unitName" label="单位名称" min-width="150">
        </el-table-column>
        <el-table-column prop="inServicePersonCount" width="150" label="招聘计划数" align="center" >
          <template slot-scope="scope">
            {{scope.row.inServicePersonCount?scope.row.inServicePersonCount:''}}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120" v-if="userType==2&&state===0" key="edit3">
          <template slot-scope="scope">
            <el-dropdown split-button  @click="handleDetail(scope.row,2)" size="small" type="primary" :loading="btnLoading">
              修改
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleDel(scope.row.id)" >删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <div v-if="userType==2&&state===0">
      <el-upload
        style="width:800px;margin-bottom:10px;"
        ref="upload1"
        :action="this.$http.defaults.baseURL+this.$http.defaults.recruitAPI +'api/recruitGenFileInfo/upload'"
        :on-success="handleUploadSucc"
        :on-remove="handleRemove"
        :before-remove="beforeRemove"
        :on-error="uploadError"
        :before-upload="beforeUpload"
        accept="application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-works,.wps"
        :show-file-list="false"
      >
        <el-button type="primary" :loading="saveloading">上传</el-button>
        <!-- <div slot="tip" class="el-upload__tip">注：支持上传word/pdf/wps文件</div>
        <div style="clear:both" /> -->
      </el-upload>
    </div>
    <div v-if="!fileListLoading">
      <template v-if="files&&files.length>0">
        <div v-for="(item,index) in files" :key="index" style="line-height:40px">
          <a href="javascript:void(0)" @click="download(item.id)"><i class="el-icon-paperclip" /> {{item.fileName}}.{{item.fileType}}</a>
          <el-button v-if="userType==2&&state===0" style="margin-left:10px" size="mini" type="danger" @click="beforeRemove(item)">删除</el-button>
          <!-- <template v-if="item.fileType==='pdf'"><i style="cursor: pointer;" class="el-icon-search" @click="showfile(item.id)" /></template> -->
        </div>
      </template>
    </div>
    <div v-else>加载中...</div>
    <template v-if="userType==2">
      <template v-if="state===0">
        <el-button icon="el-icon-s-promotion" type="success" style="margin-top:20px" @click="setState(1)" v-if="planDeclareState===1" :loading='btnLoading'>下达</el-button>
        <span v-else>请在填报单位计划申报提交后再进行计划下达操作</span>
      </template>
      <el-button icon="el-icon-back" type="danger" style="margin-top:20px" @click="setState(0)" :loading='btnLoading' v-else>撤回</el-button>
    </template>
    <!-- <div v-else style="padding:20px; font-size:14px;color:#999;text-align:center">暂无数据</div> -->
  </div>
</template>
<script>
import qs from 'qs'
export default {
  props: {
    batchState: null,
    timestamp: '',
    userType: null,
    unitId: null,
    type: null,
    theYear: null,
    unitBeijing: null,
    planDeclareState: 0
  },
  data () {
    return {
      stepBatchId: null,
      state: null,
      dialogUnitBeijing: null,
      fileListLoading: false,
      saveloading: false,
      files: [],
      dialogTitle: '新增',
      editLoading: false,
      theType: null,
      fileList: [],
      btnLoading: false,
      editForm: {
        id: null,
        unitName: '',
        inServicePersonCount: null,
        countBeijing1: null,
        countBeijing2: null,
        countBeijing3: null,
        countBeijing4: null,
        countBeijing5: null,
        count1: null,
        count2: null,
        count3: null,
        count4: null,
        count5: null
      },
      editFormRules: {
        unitName: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        inServicePersonCount: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        countBeijing1: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        countBeijing2: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        countBeijing3: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        countBeijing4: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        countBeijing5: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        count1: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        count2: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        count3: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        count4: [
          { required: true, message: '必填', trigger: 'blur' }
        ],
        count5: [
          { required: true, message: '必填', trigger: 'blur' }
        ]
      },
      editFormVisible: false,
      addFormVisible2: false,
      startYear: '2021',
      list1: [],
      list2: [],
      list3: [],
      topersonlist: [],
      activeNameHuiqian: 'Fangan',
      huiqiandata: {
        Fangan: {},
        HS_HuiYiYiCheng: {}
      },
      Fangansrc: '',
      showPDFVisible: false,
      YijianDuixiang: '全部（总结提炼）',
      listLoading: false,
      BanziPersonName: '全部',
      pdfviewersrc: '',
      TanhuaDuixiang: '全部',
      pdfpage: 1,
      FujianFilename: '',
      pdfviewersrcFujian: '',
      showPDFVisibleFujian: false
    }
  },
  watch: {
    timestamp (val) {
      console.log('加载计划下达')
      this.getStepBatch()
      this.getList()
      this.getFileList()
    },
    userType (val) {
      console.log(val)
    },
    type (val) {
      console.log(val)
    },
    unitId (val) {
      console.log(val)
    },
    theYear (val) {
      console.log(val)
    },
    batchState (val) {
      console.log(val)
    },
    unitBeijing (val) {
      console.log(val)
    },
    planDeclareState (val) {
      console.log(val)
    }
  },
  methods: {
    getStepBatch () {
      let para = {
        'pageNum': 1,
        'pageSize': 1,
        'step': 'bus_plan_release',
        'theYear': this.theYear,
        'unitId': this.unitId
      }
      this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPostStepBatch/queryByPage`, para).then(response => {
        console.log(response.data.success)
        if (response.data.success === true) {
          this.state = response.data.result.records[0] ? response.data.result.records[0].state : 0
          this.stepBatchId = response.data.result.records[0] ? response.data.result.records[0].id : null
        } else {
          console.log('获取当前环节状态失败:' + response.data.message)
          this.$message({
            message: '获取当前环节状态失败:' + response.data.message,
            type: 'error'
          })
        }
      }).catch(error => {
        console.log(error)
        this.$message({
          message: '获取当前环节状态失败:' + error,
          type: 'error'
        })
      })
    },
    handleExport (type, unitBeijing) {
      unitBeijing = unitBeijing || 0
      let para = {
        unitId: this.unitId,
        theYear: this.theYear,
        unitBeijing: unitBeijing,
        type: type
      }
      window.open(this.$http.defaults.baseURL + this.$http.defaults.recruitAPI + 'api/recruitBusPlanRelease/export?' + qs.stringify(para))
    },
    beforeUpload (file) {
      console.log('文件类型')
      console.log(file.name)
      const isFormat = file.name.indexOf('.docx') > 0 || file.name.indexOf('.doc') > 0 || file.name.indexOf('.pdf') > 0 || file.name.indexOf('.DOCX') > 0 || file.name.indexOf('.DOC') > 0 || file.name.indexOf('.PDF') > 0 || file.name.indexOf('.wps') > 0 || file.name.indexOf('.WPS') > 0
      const isLt500M = file.size / 1024 / 1024 < 60
      if (!isLt500M) {
        this.$message.error('单个附件不能超过60M!')
      } else {
        this.saveloading = true
      }
      if (!isFormat) {
        this.$message.error('附件格式必须为word、pdf、wps!')
      } else {
        this.saveloading = true
      }
      return isFormat && isLt500M
    },
    async handleUploadSucc (response, file, fileList) {
      if (response.success) {
        let para = {
          id: response.result[0].id,
          unitId: this.unitId,
          businessStep: 'bus_plan_release',
          theYear: this.theYear
        }
        this.$http.post(this.$http.defaults.recruitAPI + `api/recruitGenFileInfo/save`, para).then(res => {
          this.saveloading = false
          if (res.data.success === true) {
            // response.result.forEach(item => {
            //   this.files.push({id: item.id, fileName: item.fileName, fileType: item.fileType})
            // })
            this.$message({
              message: '上传成功！',
              type: 'success'
            })
            this.getFileList()
          } else {
            console.log('上传失败:' + res.data.message)
            this.$message({
              message: '上传失败:' + res.data.message,
              type: 'error'
            })
          }
        })
          .catch(error => {
            this.saveloading = false
            console.log(error)
            this.$message({
              message: '上传失败:' + error,
              type: 'error'
            })
          })
      } else {
        this.saveloading = false
        this.$message({
          message: '上传失败:' + response.message,
          type: 'error'
        })
      }
    },
    beforeRemove (file) {
      // if (file && file.status === 'success') {
      //   return this.$confirm(`确定删除 ${file.name}？`)
      // }
      this.$confirm('确定删除' + file.fileName + '.' + file.fileType + '？', '提示', {
        type: 'warning'
      }).then(() => {
        this.handleRemove(file.id)
      })
    },
    handleRemove (id) {
      const url = 'api/recruitGenFileInfo/remove?id=' + id
      this.$http.get(this.$http.defaults.recruitAPI + url).then(res => {
        console.log('删除成功:', res)
        if (res.data.success === true) {
          this.getFileList()
          this.$message({
            message: '删除成功！',
            type: 'success'
          })
        }
      })
    },
    // handleRemove (file, fileList) {
    //   console.log('file')
    //   console.log(file)
    //   if (file && file.status === 'success') {
    //     let fileid = file.id ? file.id : file.response.result[0].id
    //     const url = 'api/newFileInfo/remove?id=' + fileid
    //     this.$http.get(this.$http.defaults.recruitAPI + url).then(res => {
    //       console.log('删除成功:', res)
    //       if (res.data.success === true) {
    //         this.files = this.files.filter(item => item.id !== fileid)
    //         this.$message({
    //           message: '删除成功！',
    //           type: 'success'
    //         })
    //       }
    //     })
    //   }
    // },
    uploadError (err) {
      this.saveloading = false
      console.log(err)
      this.$message({
        message: '上传失败:' + err,
        type: 'error'
      })
    },
    download (id) {
      window.open(this.$http.defaults.baseURL + this.$http.defaults.recruitAPI + 'api/recruitGenFileInfo/download?id=' + id)
    },
    handleDel (id) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        let para = {ids: [id]}
        this.listLoading = true
        this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPlanRelease/remove`, para).then(response => {
          if (response.data.success === true) {
            this.addLoading = false
            this.$message({
              message: '删除成功',
              type: 'success'
            })
          } else {
            console.log('删除失败:' + response.data.message)
            this.$message({
              message: '删除失败:' + response.data.message,
              type: 'error'
            })
          }
          this.getList()
        })
          .catch(error => {
            console.log(error)
            this.$message({
              message: '删除失败:' + error,
              type: 'error'
            })
          })
      })
    },
    handleDetail (obj, theType, unitBeijing) {
      this.dialogTitle = '修改'
      this.editForm.id = obj.id
      this.editForm.unitName = obj.unitName
      this.editForm.inServicePersonCount = obj.inServicePersonCount
      this.editForm.countBeijing1 = obj.countBeijing1
      this.editForm.countBeijing2 = obj.countBeijing2
      this.editForm.countBeijing3 = obj.countBeijing3
      this.editForm.countBeijing4 = obj.countBeijing4
      this.editForm.countBeijing5 = obj.countBeijing5
      this.editForm.count1 = obj.count1
      this.editForm.count2 = obj.count2
      this.editForm.count3 = obj.count3
      this.editForm.count4 = obj.count4
      this.editForm.count5 = obj.count5
      this.theType = theType
      this.dialogUnitBeijing = unitBeijing
      this.editFormVisible = true
    },
    handleAdd (theType, unitBeijing) {
      this.dialogTitle = '新增'
      this.editForm.id = null
      this.editForm.unitName = ''
      this.editForm.inServicePersonCount = 0
      this.editForm.countBeijing1 = 0
      this.editForm.countBeijing2 = 0
      this.editForm.countBeijing3 = 0
      this.editForm.countBeijing4 = 0
      this.editForm.countBeijing5 = 0
      this.editForm.count1 = 0
      this.editForm.count2 = 0
      this.editForm.count3 = 0
      this.editForm.count4 = 0
      this.editForm.count5 = 0
      this.theType = theType
      this.dialogUnitBeijing = unitBeijing
      this.editFormVisible = true
    },
    editFormSubmit () {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          this.editLoading = true
          let para = {
            id: this.editForm.id,
            inServicePersonCount: this.editForm.inServicePersonCount,
            countBeijing1: this.editForm.countBeijing1,
            countBeijing2: this.editForm.countBeijing2,
            countBeijing3: this.editForm.countBeijing3,
            countBeijing4: this.editForm.countBeijing4,
            countBeijing5: this.editForm.countBeijing5,
            count1: this.editForm.count1,
            count2: this.editForm.count2,
            count3: this.editForm.count3,
            count4: this.editForm.count4,
            count5: this.editForm.count5,
            unitName: this.editForm.unitName,
            theType: this.theType,
            unitId: this.unitId,
            theYear: this.theYear,
            unitBeijing: this.theType === 1 ? this.dialogUnitBeijing : null
          }
          this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPlanRelease/save`, para).then(response => {
            console.log(response.data.success)
            if (response.data.success === true) {
              this.$message({
                message: '保存成功',
                type: 'success'
              })
              this.editFormVisible = false
              this.editLoading = false
              this.getList()
            } else {
              console.log('保存失败:' + response.data.message)
              this.$message({
                message: '保存失败:' + response.data.message,
                type: 'error'
              })
              this.editLoading = false
            }
          }).catch(error => {
            console.log(error)
            this.$message({
              message: '保存失败:' + error,
              type: 'error'
            })
            this.editLoading = false
          })
        }
      })
    },
    getNum (i) {
      return i < 10 ? '0' + i : i
    },
    setState (state) {
      if (this.list1.length === 0 && this.list2.length === 0 && this.list3.length === 0 && this.files.length === 0) {
        this.$message({
          message: '操作失败:您未填写任何信息',
          type: 'error'
        })
        return false
      }
      this.$confirm('确认' + (state === 1 ? '下达' : '撤回') + '吗?', '提示', {
        type: 'warning'
      }).then(() => {
        let para = {
          id: this.stepBatchId,
          state: state,
          theYear: this.theYear,
          unitId: this.unitId,
          step: 'bus_plan_release'
        }
        this.btnLoading = true
        this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPostStepBatch/save`, para).then(response => {
          if (response.data.success === true) {
            if (state === 1) {
              this.$http.get(this.$http.defaults.recruitAPI + 'api/recruitBusPost/buildPostData?theYear=' + this.theYear + '&unitId=' + this.unitId).then(response => {
                this.btnLoading = false
                if (response.data.success === true) {
                  this.$message({
                    message: '操作成功',
                    type: 'success'
                  })
                  this.backFormVisible = false
                  this.$emit('getDetails')
                } else {
                  console.log('操作失败:' + response.data.message)
                  this.$message({
                    message: '操作失败:' + response.data.message,
                    type: 'error'
                  })
                }
              }).catch(error => {
                this.btnLoading = false
                console.log(error)
                this.$message({
                  message: '操作失败:' + error,
                  type: 'error'
                })
              })
            } else {
              this.btnLoading = false
              this.$message({
                message: '操作成功',
                type: 'success'
              })
              this.backFormVisible = false
              this.$emit('getDetails')
            }
          } else {
            this.btnLoading = false
            console.log('操作失败:' + response.data.message)
            this.$message({
              message: '操作失败:' + response.data.message,
              type: 'error'
            })
          }
        }).catch(error => {
          this.btnLoading = false
          console.log(error)
          this.$message({
            message: '操作失败:' + error,
            type: 'error'
          })
        })
      })
    },
    // showfile (filename, filepathname) {
    //   window.open(this.$http.defaults.baseURL + this.$http.defaults.recruitAPI + 'api/shenghuohui/getfujian?unitId=' + this.$route.params.id + '&filepathname=' + filepathname + '&t=' + new Date())
    // },
    getFileList () {
      this.fileListLoading = true
      let para = {
        unitId: this.unitId,
        businessStep: 'bus_plan_release',
        theYear: this.theYear
      }
      this.$http.post(this.$http.defaults.recruitAPI + `api/recruitGenFileInfo/getFiles`, para).then(response => {
        this.fileListLoading = false
        if (response.data.success === true) {
          this.files = response.data.result
        } else {
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
      }).catch(error => {
        console.log(error)
        this.$message({
          message: '网络获取失败:' + error,
          type: 'error'
        })
        this.fileListLoading = false
      })
    },
    getList () {
      this.listLoading = true
      let para = {
        pageNum: 1,
        pageSize: 1000,
        unitId: this.unitId,
        theYear: this.theYear,
        theType: 1,
        unitBeijing: 1
      }
      this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPlanRelease/queryByPage`, para).then(response => {
        this.listLoading = false
        if (response.data.success === true) {
          this.list1 = response.data.result.records
          this.list1.forEach((item, index, arr) => {
            arr[index].sum1 = item.countBeijing1 + item.countBeijing2 + item.countBeijing3 + item.countBeijing4 + item.countBeijing5
            arr[index].countBeijing34 = item.countBeijing3 + item.countBeijing4
            arr[index].sum2 = item.count1 + item.count2 + item.count3 + item.count4 + item.count5
            arr[index].count34 = item.count3 + item.count4
          })
        } else {
          console.log('获取数据失败:' + response.data.message)
          this.$message({
            message: '获取数据失败:' + response.data.message,
            type: 'error'
          })
        }
      })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
          this.listLoading = false
        })
      this.listLoading = true
      para = {
        pageNum: 1,
        pageSize: 1000,
        unitId: this.unitId,
        theYear: this.theYear,
        theType: 1,
        unitBeijing: 2
      }
      this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPlanRelease/queryByPage`, para).then(response => {
        this.listLoading = false
        if (response.data.success === true) {
          this.list2 = response.data.result.records
          this.list2.forEach((item, index, arr) => {
            arr[index].count34 = item.count3 + item.count4
            arr[index].sum2 = item.count1 + item.count2 + item.count3 + item.count4 + item.count5
          })
        } else {
          console.log('获取数据失败:' + response.data.message)
          this.$message({
            message: '获取数据失败:' + response.data.message,
            type: 'error'
          })
        }
      })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
          this.listLoading = false
        })
      this.listLoading = true
      para = {
        pageNum: 1,
        pageSize: 1000,
        unitId: this.unitId,
        theYear: this.theYear,
        theType: 2
      }
      this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusPlanRelease/queryByPage`, para).then(response => {
        this.listLoading = false
        if (response.data.success === true) {
          this.list3 = response.data.result.records
        } else {
          console.log('获取数据失败:' + response.data.message)
          this.$message({
            message: '获取数据失败:' + response.data.message,
            type: 'error'
          })
        }
      })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
          this.listLoading = false
        })
    }
  }
}
</script>
<style scoped>
  .mytable{
    border-top: 1px solid #74a6cc;
    border-left: 1px solid #74a6cc;
    margin:0 10px 10px;
    width: calc(100% - 20px);
  }
  .mytable th{
    padding: 10px;
    border-right: 1px solid #74a6cc;
    border-bottom: 1px solid #74a6cc;
    vertical-align: top;
    line-height: 150%;
    background: #FAFAFA;
    width:200px;
    text-align:right;
  }
  .mytable td{
    padding: 10px;
    border-right: 1px solid #74a6cc;
    border-bottom: 1px solid #74a6cc;
    vertical-align: top;
    line-height: 150%;
  }
</style>
<style>
#recruitTable .el-table{
  border:1px solid #95B8E7 !important;
}
#recruitTable .el-table td, #recruitTable .el-table th{
  border-right:1px solid #95B8E7 !important;
  border-bottom:1px solid #95B8E7 !important;
}
</style>
